﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PFI.ADCConv;
using PFI.DAConv;
using PFI.SCHVN;
using PFI.RegisterDevice;
using Utils.RamDevice;
using Utils.BinaryToSchvnCodeConverter;

namespace Algorithm.CalibrationWeights
{
    public class CalibratorOfTrackingCombinations
    {
        ADC adcInst;
        //NotationSystem binarySys;
        //NotationSystem schvnSys;
        Converter bToSchvnConv;
        BinaryRegister binaryReg;

        public CalibratorOfTrackingCombinations(ADC adcInst)
        {
            this.adcInst = adcInst;

            int binaryN = (int)Math.Ceiling(Math.Log(adcInst.dac.schvn.alpha, Math.E) * adcInst.dac.schvn.n / Math.Log(2, Math.E));
            NotationSystem binarySys = new NotationSystem(binaryN, 2, 0);
            binaryReg = new BinaryRegister(binarySys);

            bToSchvnConv = new Converter(binarySys, adcInst.dac.schvn);
        }
        public void CalibrateTrackingCombinations()
        {
            RAM.TrackingCombinations.ClearTrackingCombinations();

            binaryReg.SetPolinomNull();
            int ik;
            SCHVNRegister schvnReg;

            for (ik = 0; !binaryReg.isMaxValueInRegister(); ik++,binaryReg.AddOne())
            {
                schvnReg = bToSchvnConv.Convert(binaryReg);
                int res = binaryReg.GetBinaryValue();
                RAM.TrackingCombinations.AddCombination(binaryReg.GetBinaryValue(), schvnReg.polinom as int[]);
            }
            schvnReg = bToSchvnConv.Convert(binaryReg);
            RAM.TrackingCombinations.AddCombination(binaryReg.GetBinaryValue(), schvnReg.polinom as int[]);
        }
    }
}
